package com.soap.desensitize.posterity.collection;

import com.soap.desensitize.encry.IDesensitization;
import com.soap.desensitize.exception.strategy.DecodeException;
import com.soap.desensitize.exception.strategy.EncodeException;
import com.soap.desensitize.posterity.AbstractPosterity;
import com.soap.desensitize.strategy.rreversible.symmetry.DesStrategy;

import java.util.ArrayList;
import java.util.List;

/**
 * @desc List加密
 */
public class ListDesensitization<T extends Object> extends AbstractPosterity<List<T>> {
    /**
     * @desc 无参构造器，默认使用DES加密
     */
    private ListDesensitization() {
        super(DesStrategy.getInstance());
    }

    private static ListDesensitization<Object> instance = null;
    /**
     * @desc 获得实例
     * @return 实例
     */
    public static synchronized ListDesensitization getInstance(IDesensitization encry){
        if(instance == null){
            instance = new ListDesensitization();
        }
        return instance;
    }
    /**
     * @param encry
     * @desc 有参构造器
     */
    public ListDesensitization(IDesensitization encry) {
        super(encry);
    }

    @Override
    public List<T> encode(List data) throws EncodeException {
        List list=new ArrayList();
        for (Object value: data) {
            Object encodeValue = judgeAndEncode(value);
            list.add(encodeValue);
        }
        return list;
    }

    @Override
    public List decode(List data) throws DecodeException {
        List list=new ArrayList();
        for (Object value: data) {

            Object decodeValue = judgeAndDecode(value);

            list.add(decodeValue);
        }
        return list;
    }
}
